<?php
namespace Kuoqi\Dom{
use DOMXPath;
class DomDocument extends \DOMDocument{
	public $version = '1.00.00';
	public $dom;
	//这里是class的基本方法
	public $actNodeList;
	public $actSelector;
	public $actType;
	//查找元素,根据标签查找
	public function find($code){
		return $this->querySelector($code);
	}
	
	//这里是核心脚本信息，这里面的方法，包含domDocuemnt与系统自定义方法的混合，是比较复杂的
	//使用选择器，
	public function querySelector($seletor){
		$this->actSelector = DomSelector::getSelector($seletor);
		$nodelist = new DomNodelist();
		$nodelist->push($this->getElementsByTagName('html')->item(0));
		$nodelist = $nodelist->querySelector($seletor);
		return $nodelist;
	}
	//找到顶部节点
	public function top(){
		$nodelist = new DomNodelist();
		$nodelist->push($this->getElementsByTagName('html')->item(0));
		$this->actNodeList = $nodelist;
		return $this;
	}
	//item
	public function item($index)
	{
		return $this->actNodeList->item($index);	
	}
	//尝试找到自己的父级节点
	public function parents($code){
		
	}
	//获取已收获的节点信息
	public function getNodes(){
		return $this->actNodeList;
	}
	//尝试获取当前节点的文本内容
	public function getText(){
		return $this->actNodeList->text();	
	}
	//尝试获取属性
	public function getAttr($attrName){
		return $this->actNodeList->getAttr($attrName);	
	}
	//获取当前长度
	public function getLength(){
		return $this->actNodeList->getLength();	
	}
	//冲刷出效果
	public function output(){
		return $this->saveHTML();
	}
	//获取title
	public function getTitle(){
		return $this->querySelector('title')->text();
	}
}}